@extends("admin.base")
@section("page")
    <div class="container-fluid p-4">
        <h3>电影信息管理页面</h3>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <a href="movieaddpage">
                            <button class="btn btn-primary waves-effect"> 添加电影</button>
                        </a>
                        <div class="table-responsive mt-3">
                            <table class="table mb-0">
                                <thead>
                                <tr>
                                    <th>#</th>
                                    <th>中文名称</th>
                                    <th>维吾尔文名称</th>
                                    <th>图片</th>
                                    <th>类型</th>
                                    <th>国籍</th>
                                    <th>年份</th>
                                    <th>简介</th>
                                    <th>语言</th>
                                    <th>得分</th>
                                    <th>创建时间</th>
                                    <th>更新时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($movies as $movie)
                                    <tr style="line-height: 40px;">
                                        <th scope="row">{{$movie->id}}</th>
                                        <td>{{$movie->name_ch}}</td>
                                        <td>{{$movie->name_uy}}</td>
                                        <td><img src="{{$movie->img}}" width="40px" height="40px" alt=""></td>
                                        <td>{{$movie->typeName}}</td>
                                        <td>{{$movie->countryName}}</td>
                                        <td>
                                            @switch($movie->year)
                                                @case(1) 1980
                                                @break
                                                @case(2) 1990
                                                @break
                                                @case(3) 2000
                                                @break
                                                @case(4) 2010
                                                @break
                                                @case(5) 2020
                                                @break
                                                @case(6) 2021
                                                @break
                                            @endswitch
                                        </td>
                                        <td>{{$movie->description}}</td>
                                        <td>
                                            @switch($movie->lang)
                                                @case(1) 英语
                                                @break
                                                @case(2) 国语
                                                @break
                                                @case(3) 维吾尔语
                                                @break
                                                @case(4) 哈萨克语
                                                @break
                                                @case(5) 柯尔克孜语
                                                @break
                                                @case(6) 乌兹别克语
                                                @break
                                            @endswitch</td>
                                        <td>{{$movie->score/10}}</td>
                                        <td>{{$movie->created_at}}</td>
                                        <td>{{$movie->updated_at}}</td>
                                        <td>
                                            <a href="movieaddpage?id={{$movie->id}}">
                                                <button class="btn btn-success"> 编辑</button>
                                            </a>
                                            <button onclick="del({{$movie->id}})" class="btn btn-danger"> 删除</button>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <nav aria-label="Page navigation example">
                                <ul class="pagination">
                                    <li class="page-item"><a class="page-link" href="kino?page={{max(1,$page-1)}}">上一页</a></li>
                                    @for($p=1;$p<=$maxPage;$p++)
                                    <li class="page-item"><a class="page-link {{$p==$page?'yursun':''}}" href="kino?page={{$p}}">{{$p}}</a></li>
                                    @endfor
                                    <li class="page-item"><a class="page-link" href="kino?page={{min($page+1,$maxPage)}}">下一页</a></li>
                                </ul>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>
@endsection

@section("scripts")
    <style>
        .swal-footer {
            text-align: center;
            padding-top: 13px;
            margin-top: 13px;
            padding: 13px 16px;
            border-radius: inherit;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }
        .yursun{
            background-color: rebeccapurple;
            color: white;
        }
    </style>
    <script>
        function del(id) {
            swal({
                title: "确认操作",
                text: "如果数据被删除，无法恢复，确认删除吗",
                icon: "warning",
                buttons: ["取消", "删除"],
            }).then((willDelete) => {
                if (willDelete) {
                    $.ajax({
                        url: "http://sahar.aynakedu.com/moviedelete",    //请求的url地址
                        dataType: "json",   //返回格式为json
                        async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                        headers: {'X-CSRF-TOKEN': '{{csrf_token()}}'},
                        data: {"id": id},    //参数值
                        type: "GET",   //请求方式
                        success: function (req) {
                            if (req.err == 0) {
                                swal({
                                    title: "操作成功",
                                    text: "电影信息删除成功！",
                                    icon: "success",
                                    button: "知道了",
                                });
                                setTimeout(function () {
                                    location.reload();
                                }, 2000)
                            }
                        },
                        error: function (err) {
                            //请求出错处理
                        }
                    });
                } else {

                }
            });
        }
    </script>
@endsection
